package com.iwomy.envpro.platform.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.envpro.common.core.constant.CacheConstants;
import com.iwomy.envpro.common.core.util.R;
import com.iwomy.envpro.common.log.annotation.SysLog;
import com.iwomy.envpro.platform.entity.TelecomTianyiAiotEntity;
import com.iwomy.envpro.platform.service.TelecomTianyiAiotService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.security.access.prepost.PreAuthorize;
import com.iwomy.envpro.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电信天翼AIOT
 *
 * @author pig
 * @date 2023-12-28 10:32:38
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/telecomTianyiAiot")
@Tag(description = "telecomTianyiAiot", name = "电信天翼AIOT管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class TelecomTianyiAiotController {

	private final TelecomTianyiAiotService telecomTianyiAiotService;

	/**
	 * 分页查询
	 *
	 * @param page              分页对象
	 * @param telecomTianyiAiot 电信天翼AIOT
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('platform_telecomTianyiAiot_view')")
	public R getTelecomTianyiAiotPage(@ParameterObject Page page, @ParameterObject TelecomTianyiAiotEntity telecomTianyiAiot) {
		LambdaQueryWrapper<TelecomTianyiAiotEntity> wrapper = Wrappers.lambdaQuery();
		return R.ok(telecomTianyiAiotService.page(page, wrapper));
	}


	/**
	 * 通过id查询电信天翼AIOT
	 *
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('platform_telecomTianyiAiot_view')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(telecomTianyiAiotService.getById(id));
	}

	/**
	 * 新增电信天翼AIOT
	 *
	 * @param telecomTianyiAiot 电信天翼AIOT
	 * @return R
	 */
	@Operation(summary = "新增电信天翼AIOT", description = "新增电信天翼AIOT")
	@SysLog("新增电信天翼AIOT")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('platform_telecomTianyiAiot_add')")
	public R save(@RequestBody TelecomTianyiAiotEntity telecomTianyiAiot) {
		return R.ok(telecomTianyiAiotService.save(telecomTianyiAiot));
	}

	/**
	 * 修改电信天翼AIOT
	 *
	 * @param telecomTianyiAiot 电信天翼AIOT
	 * @return R
	 */
	@Operation(summary = "修改电信天翼AIOT", description = "修改电信天翼AIOT")
	@SysLog("修改电信天翼AIOT")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('platform_telecomTianyiAiot_edit')")
	@CacheEvict(value = "telecom_tianyi_Aiot", key = "#telecomTianyiAiot.imei")
	public R updateById(@RequestBody TelecomTianyiAiotEntity telecomTianyiAiot) {
		return R.ok(telecomTianyiAiotService.updateById(telecomTianyiAiot));
	}

	/**
	 * 通过id删除电信天翼AIOT
	 *
	 * @param ids id列表
	 * @return R
	 */
	@Operation(summary = "通过id删除电信天翼AIOT", description = "通过id删除电信天翼AIOT")
	@SysLog("通过id删除电信天翼AIOT")
	@DeleteMapping
	@PreAuthorize("@pms.hasPermission('platform_telecomTianyiAiot_del')")
	@CacheEvict(value = "telecom_tianyi_Aiot", allEntries = true)
	public R removeById(@RequestBody Long[] ids) {
		return R.ok(telecomTianyiAiotService.removeBatchByIds(CollUtil.toList(ids)));
	}


	/**
	 * 导出excel 表格
	 *
	 * @param telecomTianyiAiot 查询条件
	 * @return excel 文件流
	 */
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('platform_telecomTianyiAiot_export')")
	public List<TelecomTianyiAiotEntity> export(TelecomTianyiAiotEntity telecomTianyiAiot) {
		return telecomTianyiAiotService.list(Wrappers.query(telecomTianyiAiot));
	}
}